package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.NewsRecord;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.NewsRecordService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller //@Controller注解是用spring容器生成 对象 默认对象名 newsRecordController
@RequestMapping("/newsRecordController") //@RequestMapping 用户请求查找该资源使用的名字 网名 默认  /newsRecordController
public class NewsRecordController {
	@Resource
    NewsRecordService newsRecordService;
	@RequestMapping("/getAllNewsRecord")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<NewsRecord> getAllNewsRecord() throws Exception{
    	System.out.println("查询管理员");
    	return newsRecordService.getAllNewsRecords();
    }
	@RequestMapping("/addNewsRecord")
	@ResponseBody
	public DTO<NewsRecord> addNewsRecord(@RequestBody NewsRecord newsRecord) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加管理员成功");
		return newsRecordService.addNewsRecord(newsRecord);
	}

	@RequestMapping("/deleteNewsRecordByNewno/{newno}")
	@ResponseBody
    public DTO<NewsRecord> deleteNewsRecordByNewno(@PathVariable("newno") String newno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(newno+"删除管理员成功");
    	return newsRecordService.deleteNewsRecordByNewno(newno);
    }



	@RequestMapping("/getNewsRecordByNewno/{newno}")
	@ResponseBody
	public DTO<NewsRecord> getNewsRecordByNewno(@PathVariable("newno") String newno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println(newno+"根据主键查询管理员成功");
		return newsRecordService.getNewsRecordByNewno(newno);
	}

	@RequestMapping("/updateNewsRecordByNewno")
	@ResponseBody
	public DTO<NewsRecord> updateNewsRecordByNewno(@RequestBody NewsRecord newsRecord) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改管理员成功");
		System.out.println(newsRecord);
		return newsRecordService.updateNewsRecordByNewno(newsRecord);
	}

	@RequestMapping("/getNewsRecordByPage")
	@ResponseBody
	public DTO<NewsRecord> getNewsRecordByPage(PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("分页查询管理员成功");
		return newsRecordService.getNewsRecordByPage(pageInfo);
	}

}
